//
//  FirstSearTopicTableViewCell.m
//  Project_B
//
//  Created by 张闯的mac pro on 15/12/1.
//  Copyright © 2015年 张闯. All rights reserved.
//

#import "FirstSearTopicTableViewCell.h"
#import "FirstModel.h"

@interface FirstSearTopicTableViewCell ()

@property (nonatomic, strong) UILabel *nickname;
@property (nonatomic, strong) UILabel *createdate;
@end

@implementation FirstSearTopicTableViewCell

#pragma mark - 初始化
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.title = [[UILabel alloc] init];
        [self.contentView addSubview:self.title];

        
        self.nickname = [[UILabel alloc] init];
        [self.contentView addSubview:self.nickname];

        
        self.createdate = [[UILabel alloc] init];
        [self.contentView addSubview:self.createdate];

    }
    return self;
}
#pragma mark - 布局
- (void)layoutSubviews
{
    [super layoutSubviews];
    self.title.frame = CGRectMake(15, 15, self.contentView.frame.size.width - 30, 15);
    self.title.font = [UIFont systemFontOfSize:15];
    
    
    self.nickname.frame = CGRectMake(15, self.title.frame.origin.y + self.title.frame.size.height + 10, self.contentView.frame.size.width - 30, 12);
    self.nickname.font = [UIFont systemFontOfSize:12];
    self.nickname.textColor = [UIColor lightGrayColor];
    
    self.createdate.frame = CGRectMake(15, self.nickname.frame.origin.y, self.contentView.frame.size.width - 30, 12);
    self.createdate.font = [UIFont systemFontOfSize:12];
    self.createdate.textAlignment = NSTextAlignmentRight;
    self.createdate.textColor = [UIColor lightGrayColor];
    
}
- (void)setTopicModel:(FirstModel *)topicModel
{
    if (_topicModel != topicModel) {
        _topicModel = topicModel;
    }
    self.nickname.text = topicModel.nickname;
    self.createdate.text = [NSString stringWithFormat:@"%@ 发布于 %@", topicModel.createdate, topicModel.clubname];
    //关键字高亮
    NSString *string = topicModel.title;
    NSMutableAttributedString *newString = [[NSMutableAttributedString alloc] initWithString:string];
    //得到关键字位置
    NSRange range = [string rangeOfString:self.searchText];
    [newString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:60.0 / 255 green:149.0 / 255 blue:58.0 / 255 alpha:1] range:range];
    self.title.textColor = [UIColor grayColor];
    self.title.attributedText = newString;
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
